package com.jia.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;


/**
 * @author 1038940655
 * @create 2021/1/13 17:55
 */
//这个主启动类区别与有了hystrix熔断机制
@SpringBootApplication
@EnableEurekaClient//开启这个和Server对应，自动注册到eureka服务中去了
//@ComponentScan("com.jia.springcloud.dao")//不知道为啥非要加这个dao接口的bean才能spring扫描到
@EnableDiscoveryClient//发现微服务
@EnableCircuitBreaker//添加对熔断的支持
public class DeptProviderHystrix_8001 {
    public static void main(String[] args) {

        SpringApplication.run(DeptProviderHystrix_8001.class,args);
    }

//    增加一个servlet就是将这个服务的请求添加到监控页面，监控页面就可以监视这个服务的请求状况（固定写法）
     @Bean
     public ServletRegistrationBean hystrixMetricsStreamServlet(){
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
    //访问该页面就是监控页面
    registrationBean.addUrlMappings("/actuator/hystrix.stream");
    return registrationBean;
}
}
